/*
 * =====================================================================================
 *
 *       Filename:  socket.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  07/20/2012 07:43:32 PM
 *       Revision:  none
 *       Compiler:  gcc/g++
 *
 *         Author:  wangtengchao , wangtengchao AT gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef SOCKET_H
#define SOCKET_H
#include"inetAddr.h"
#include<sys/types.h>
#include<sys/socket.h>
#include<unistd.h>
#include<boost/noncopyable.hpp>
namespace inm
{
	namespace net
	{
		class InetAddr;
        class Socket : boost::noncopyable
		{
			public:
                Socket();//will create a sockfd
                explicit Socket(const InetAddr& serverAddr);//only used by accept
                explicit Socket(int sockfd)
                {//used by tcpconnect  because it's fd is passed by connfd=accept
					sockfd_ = sockfd;	
				}
                ~Socket();
                void bind(const InetAddr& serverAddr);//bind sockfd and serverAddr
                void listen();//if use i/o multiplexing.this is no use
                int accept(InetAddr& clientAddr);//return connfd  and clientAddr
				void setNoDelay(bool b);
                int getSockFd() const
                {
                    return sockfd_;
                }
			private:
				int sockfd_;
                bool isBind_;
		};
	};
};
#endif

